<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Motor control example</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51 General Code Examples
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('group__simple__motor__control.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#define-members">Defines</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Motor control example</div>  </div>
<div class="ingroups"><a class="el" href="group__nrf__examples__nrf6310.html">nRF6310 example projects</a></div></div>
<div class="contents">

<p>Example of PWM waveform generation where timer resets after each full period. Setup: Standard setup except LED 0 should be connected to pin 18 (port 2, pin 2)  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="define-members"></a>
Defines</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#gaf1aeb7e936e859c23ed991a5710cb38f">PWM_OUTPUT_PIN_NUMBER</a>&#160;&#160;&#160;(18UL)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#gaa7914b8d7fd0bae056b85acb5062676b">TIMER_PRESCALER</a>&#160;&#160;&#160;(4)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#ga871ccc78714a478abd2a8e11340693f3">LED_INTENSITY_HIGH</a>&#160;&#160;&#160;(224U)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#ga8d90fa917b5e41534c88aa23d7e92ab7">LED_INTENSITY_LOW</a>&#160;&#160;&#160;(32U)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#ga80700bb63bd56ebabbb4728aa433fd29">LED_OFF</a>&#160;&#160;&#160;(1U)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#gaa98bd74144aab58a816ab925243bb926">LED_INTENSITY_HALF</a>&#160;&#160;&#160;(128U)</td></tr>
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#gaace1ec7562b6ea02c189b5dea139de82">pwm_set</a> (uint8_t new_setting)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#ga9459bbd9d6c1f423f968799c09f96434">timer2_init</a> (void)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#gad22626704ea5d45f863163500e355cc3">gpiote_init</a> (void)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#gaad16890c50156256e260b5205571ddc4">ppi_init</a> (void)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__simple__motor__control.html#ga12c8b827e5eab9d3f93d56f858e735a3">TIMER2_IRQHandler</a> (void)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga840291bc02cba5474a4cb46a9b9566fe"></a><!-- doxytag: member="simple_motor_control::main" ref="ga840291bc02cba5474a4cb46a9b9566fe" args="(void)" -->
int&#160;</td><td class="memItemRight" valign="bottom"><b>main</b> (void)</td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<p>Example of PWM waveform generation where timer resets after each full period. Setup: Standard setup except LED 0 should be connected to pin 18 (port 2, pin 2) </p>
<p>Behaviour: This example generates variable duty cycle pulse train on selected GPIO pin. By default the pwm waveform generation will have a duty cycle of 1/256. If Pin 1 is pressed the duty cycle is set to 224/256. If only Pin 0 is pressed the waveform will set the duty cycle to 32/256.</p>
<p>Expected Results: In the default state LED 0 should have a very weak light. When Button 1 is pressed the strenght of LED 0 is increased to a bright light. When only Button 0 is pressed LED 0 will give a medium strenght light. </p>
<hr/><h2>Define Documentation</h2>
<a class="anchor" id="gaf1aeb7e936e859c23ed991a5710cb38f"></a><!-- doxytag: member="main.c::PWM_OUTPUT_PIN_NUMBER" ref="gaf1aeb7e936e859c23ed991a5710cb38f" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define PWM_OUTPUT_PIN_NUMBER&#160;&#160;&#160;(18UL)</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Pin number for PWM output </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00039">39</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="gaa7914b8d7fd0bae056b85acb5062676b"></a><!-- doxytag: member="main.c::TIMER_PRESCALER" ref="gaa7914b8d7fd0bae056b85acb5062676b" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define TIMER_PRESCALER&#160;&#160;&#160;(4)</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Prescaler setting for timers </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00040">40</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="ga871ccc78714a478abd2a8e11340693f3"></a><!-- doxytag: member="main.c::LED_INTENSITY_HIGH" ref="ga871ccc78714a478abd2a8e11340693f3" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LED_INTENSITY_HIGH&#160;&#160;&#160;(224U)</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>High intentisty </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00041">41</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="ga8d90fa917b5e41534c88aa23d7e92ab7"></a><!-- doxytag: member="main.c::LED_INTENSITY_LOW" ref="ga8d90fa917b5e41534c88aa23d7e92ab7" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LED_INTENSITY_LOW&#160;&#160;&#160;(32U)</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Low intensity </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00042">42</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="ga80700bb63bd56ebabbb4728aa433fd29"></a><!-- doxytag: member="main.c::LED_OFF" ref="ga80700bb63bd56ebabbb4728aa433fd29" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LED_OFF&#160;&#160;&#160;(1U)</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Led off </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00043">43</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="gaa98bd74144aab58a816ab925243bb926"></a><!-- doxytag: member="main.c::LED_INTENSITY_HALF" ref="gaa98bd74144aab58a816ab925243bb926" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LED_INTENSITY_HALF&#160;&#160;&#160;(128U)</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Half intensity. Used to calculate timer parameters. </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00044">44</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="gaace1ec7562b6ea02c189b5dea139de82"></a><!-- doxytag: member="main.c::pwm_set" ref="gaace1ec7562b6ea02c189b5dea139de82" args="(uint8_t new_setting)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static void pwm_set </td>
          <td>(</td>
          <td class="paramtype">uint8_t&#160;</td>
          <td class="paramname"><em>new_setting</em></td><td>)</td>
          <td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Sets PWM duty cycle. </p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">new_setting</td><td>New duty cycle, where 128 results in 50% duty cycle. </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00049">49</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="ga9459bbd9d6c1f423f968799c09f96434"></a><!-- doxytag: member="main.c::timer2_init" ref="ga9459bbd9d6c1f423f968799c09f96434" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static void timer2_init </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Initializes Timer 2 peripheral. </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00056">56</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="gad22626704ea5d45f863163500e355cc3"></a><!-- doxytag: member="main.c::gpiote_init" ref="gad22626704ea5d45f863163500e355cc3" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static void gpiote_init </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Initializes GPIO Tasks/Events peripheral. </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00087">87</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="gaad16890c50156256e260b5205571ddc4"></a><!-- doxytag: member="main.c::ppi_init" ref="gaad16890c50156256e260b5205571ddc4" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static void ppi_init </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Initializes Programmable Peripheral Interconnect peripheral. </p>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00118">118</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="ga12c8b827e5eab9d3f93d56f858e735a3"></a><!-- doxytag: member="main.c::TIMER2_IRQHandler" ref="ga12c8b827e5eab9d3f93d56f858e735a3" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void TIMER2_IRQHandler </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p><a class="el" href="group__gpio__example.html#ga840291bc02cba5474a4cb46a9b9566fe">main()</a> function </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>0. int return type required by ANSI/ISO standard. </dd></dl>

<p>Definition at line <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html#l00147">147</a> of file <a class="el" href="nrf6310_2simple__pwm__motor__control__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
